package com.taotao.sort;

/**
 * 冒泡排序
 *
 * @author Administrator
 * @date 2020/7/24 15:25
 */
public class BubbleSort {

    public static void sort(int[] a) {
        for (int i = 0; i < a.length; i++) {
            boolean flag = false;
            for (int j = 0; j < a.length - i - 1; j++) {
                if (a[j] > a[j + 1]) {

                    int tmp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = tmp;
                    flag = true;
                }
            }

            if (!flag) {
                break;
            }
        }
    }


    public static void main(String[] args) {

    }
}
